home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
NetNews Offline 2
/
NetNews Offline Volume 2.iso
/
news
/
comp
/
std
/
c
/
698
< prev
next >
Wrap
Internet Message Format
|
1996-08-06
|
3KB
Path: inforamp.net!usenet
From: pcurran@inforamp.net (Peter Curran)
Newsgroups: comp.std.c
Subject: Re: Restrictions on qsort compare function?
Date: Fri, 05 Apr 1996 04:51:40 GMT
Organization: PSC Enterprises
Message-ID: <4k28t4$2g0@sam.inforamp.net>
References: <4iokop$h4p@lyra.csx.cam.ac.uk> <4iqjar$2m9@usenet.pa.dec.com> <4jgltp$f9l@lyra.csx.cam.ac.uk> <828644274snz@genesis.demon.co.uk>
Reply-To: pcurran@inforamp.net
NNTP-Posting-Host: ts9-02.tor.istar.ca
X-Newsreader: Forte Free Agent 1.0.82
On Thu, 04 Apr 96 18:57:54 GMT in article <828644274snz@genesis.demon.co.uk>
Lawrence Kirby <fred@genesis.demon.co.uk> (Lawrence Kirby) wrote:
>In article <4jgltp$f9l@lyra.csx.cam.ac.uk>
> jkb@mrc-lmb.cam.ac.uk "James Bonfield" writes:
>>I now agree that non antisymmetric or nontransitive sort comparison functions
>>are indeed invalid. I can see how this can be construed from the ansi
>>standard, but can also see how it's possible to construe otherwise.
>I don't. 7.10.5.2:
>"The contents of the array are sorted into ascending
> order according to a comparison function pointed to by compar".
>If the comparison function produces inconsistent results then it is at odds
>with that sentence. At best that sentence has no well-defined meaning and
>the 'sort' operation as a whole has undefined behaviour.
<snip>
From the standard:
>"The function shall return an integer less than, equal to, or greater than
> zero if the first argument is considered to be respectively less than, equal
> to, or greater than the second."
Again, agreeing that the intent was that the comparison function be consistent,
this statement does not require it. (Actually, consistent is not quite the word
I mean here - it must be consistent with a well-specified definition - that is
implied by the first quote, above - but that definition need not lead to a
comparison function that produces the same result for the same values on
successive calls, or follows other "sensible" patterns.)
There is nothing here that demands that what one "considers to be ... less
than", etc., remain static over the duration of a call to qsort(). As I
suggested earlier, one could define a ordering that is time-dependent, or
changes in some other way between calls to the comparison function. I see
nothing here that precludes a comparison function from then implementing such a
definition. As long as the comparison function produces results match the rules
that have been established for considering values to be less than, etc., each
other each time it is called, whether those rules are static or not,, the
requirements of the standard have been met.
This is clearly "language lawyering" of the worst kind. Anyone who writes such
a comparison function will almost certainly get a well-earned mess. However, I
see nothing in the standard that contradicts this interpretation. For logical
correctness, I think the definition of the comparison function needs to be
tightened, although its hardly of pressing urgency.)
--
Peter Curran pcurran@inforamp.net